package com.east.controller.staff;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.HttpResponse;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.east.bean.Staff;
import com.east.service.staff.StaffService;
import com.east.utils.PageJson;
import com.east.utils.Pagenation;
import com.east.utils.Result;
import com.east.utils.ResultUtil;
import com.github.pagehelper.Page;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;

@RestController
@RequestMapping("staff")
public class StaffController {
	@Autowired
	StaffService staffService;
	/**
	 * 全查
	 * @param pagenation
	 * @param key
	 * @param status
	 * @return
	 */
	@GetMapping("/all")
	@RequiresPermissions("staff:all")
	public Result findByAll(Pagenation pagenation,String key,String status) {
		Page<Staff> findByAll = staffService.findByAll(pagenation, key, status);
		Object pageJson = new PageJson<Staff>().pageJson(findByAll);
		return ResultUtil.success(pageJson);
	}
	/**
	 * 详情
	 * @param staff
	 * @return
	 */
	@GetMapping("/findOne")
	@RequiresPermissions("staff:findOne")
	public Result findByAllAdd(Staff staff) {
	 Staff findByStaff = staffService.findByStaff(staff);
		return ResultUtil.success(findByStaff);
	}
	/**
	 * 添加
	 * @return
	 */
	@PostMapping("add")
	@RequiresPermissions("staff:add")
	public Result SaveStaff(StaffParameter staffParameter) {
	int savaStaff = staffService.savaStaff(staffParameter);
	if(savaStaff>0) {
		return ResultUtil.success("添加成功");
	}else {
		return ResultUtil.success("添加失败");
	}
	}
	/**
	 * 修改
	 * @return
	 */
	@PostMapping("update")
	@RequiresPermissions("staff:update")
	public Result updateStaff(StaffParameter sp) {
		int findByAll = staffService.updateStaff(sp);
		if(findByAll>0) {
			return ResultUtil.success("修改成功");
		}else {
			return ResultUtil.success("修改失败");
		}
	}
	/**
	 * 删除
	 * @param staff
	 * @return
	 */
	@DeleteMapping("del")
	@RequiresPermissions("staff:del")
	public Result DelStaff(Staff staff) {
		int findByAll = staffService.delStaff(staff);
		if(findByAll>0) {
			return ResultUtil.success("删除成功");
		}else {
			return ResultUtil.success("删除失败");
		}
	}
	
	
	
	
	
	
	
	//-----------------------------------------人员统计-------------------------------------
	/**
	 * 员工信息
	 * @param pagenation
	 * @param key
	 * @param status
	 * @return
	 */
	@GetMapping("/tall")
	@RequiresPermissions("staff:tall")
	public Result findByTAll(Pagenation pagenation,String key,String did,String status) {
		Page<StaffExecl> findByAll = staffService.findByTall(pagenation, key,did ,status);
		Object pageJson = new PageJson<StaffExecl>().pageJson(findByAll);
		return ResultUtil.success(pageJson);
	}
	/**
	 * 年龄统计
	 * @return
	 */
	@GetMapping("/age")
	@RequiresPermissions("staff:age")
	public Result findByAge() {
		Map<String, Object> findByAge = staffService.findByAge();
		return ResultUtil.success(findByAge);
	}
	/**
	 * 岗位年限统计
	 * @return
	 */
	@GetMapping("/position")
	@RequiresPermissions("staff:position")
	public Result findByposition() {
		Object findByPosition = staffService.findByPosition();
		return ResultUtil.success(findByPosition);
	}
	/**
	 * 本公司在职年限统计
	 * @return
	 */
	@GetMapping("/job")
	@RequiresPermissions("staff:job")
	public Result findByjob() {
		Object findByJob = staffService.findByJob();
		return ResultUtil.success(findByJob);
	}
	/**
	 * 部门人数统计
	 * @return
	 */
	@GetMapping("/depart")
	@RequiresPermissions("staff:depart")
	public Result findBydepart() {
		Object findByJobDepartMent = staffService.findByJobDepartMent();
		return ResultUtil.success(findByJobDepartMent);
	}
	
	/**
	 * 导出
	 * @return
	 * @throws IOException 
	 */
	@GetMapping("/execl")
	public void findByExecl(HttpServletRequest request,HttpServletResponse response,String key,String did,String status) throws IOException {
		staffService.execlSelf(request, response, key, did, status);
	}
}
